/**
 * <b>项目名：</b>iotest<br/>
 * <b>包名：</b>org.iotest.main<br/>
 * <b>文件名：</b>Main.java<br/>
 * <b>版本信息：</b> @version 1.0.0<br/>
 * <b>日期：</b>2013-6-4-上午9:35:32<br/>
 * <b>Copyright (c)</b> 2013魅族公司-版权所有<br/>
 *
 */

package org.monitor.main;

import java.io.FileInputStream;
import java.net.URL;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.monitor.common.Common;

/**
 * <b>类名称：</b>Main<br/>
 * <b>类描述：</b>
 * 
 * <pre>
 </pre>
 * 
 * <br/>
 * <b>创建人：</b>张军强<br/>
 * <b>修改人：</b>张军强<br/>
 * <b>修改时间：</b>2013-6-4 上午9:35:32<br/>
 * <b>修改备注：</b><br/>
 * 
 * @version 1.0.0<br/>
 */

public class Main {
	

	private static Integer port = 8083;
	private static boolean isDebug = false;

	private static Properties sysConf = new Properties();
	private static Logger logger = Logger.getLogger(Main.class);
	//public static String email = "{'host':'smtp.163.com','user':'easyphp','pwd':'123456','from':'easyphp@163.com'}";
	public static String email = "{'host':'smtp.meizu.com','user':'jk@meizu.com','pwd':'Jk123456','from':'jk@meizu.com'}";
	public static String confPath="X:/workspace/monitor";
	public static String jsUtil="";

	/**
	 * <b>创建人：</b>张军强<br/>
	 * main<br/>
	 * <b>方法描述：</b> <br/>
	 * 
	 * @param args
	 *            void
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		
		//System.setProperty("sun.jnu.encoding", "UTF-8");
		
		
		
		//System.out.println(System.getProperties());

		//System.exit(0); 
		
		
		
		if(args.length>0){
			
	
			
		} else {
			Main.confPath=Common.getProjectPath();
		}

		init();
		
		
		isDebug= Boolean.parseBoolean( sysConf.get("debug")==null?"false": sysConf.get("debug").toString());
		

		if (sysConf.get("type").equals("server")) {
			MServer.getInstance().startService(sysConf);
		} else if (sysConf.get("type").equals("client")) {
			MClient.getInstance().startService(sysConf);
		} else if (sysConf.get("type").equals("all")) {
			MServer.getInstance().startService(sysConf);
			MClient.getInstance().startService(sysConf); 
		} else {
			logger.error("参数 type 不对 只能为 server/client");
		}

		/*
		 * int len = args.length; int pos = 0; while (pos < len) { if
		 * (args[pos].equals("-port")) { port = Integer.valueOf(args[++pos]); }
		 * else if (args[pos].equals("-debug")) { isDebug =
		 * Boolean.parseBoolean(args[++pos]); } else { ++pos; } }
		 */

	}

	/**
	 * <b>创建人：</b>张军强<br/>
	 * init<br/>
	 * <b>方法描述：</b> <br/>
	 * void
	 * 
	 * @exception
	 * @since 1.0.0
	 */

	private static void init() {

		try {
			URL resource = Main.class.getResource("/log4j.properties");
			PropertyConfigurator.configure(resource);
			//sysConf.load(Main.class.getResourceAsStream("/config.properties"));
			sysConf.load(new FileInputStream(Main.confPath+"/conf/config.properties"));
		} catch (Exception e) {
			logger.error("加载配置文件出错！"+e.getMessage());
		}

	}
	
	public static Properties getConfig(){
		return sysConf;
	}
	
	public static boolean isDebug(){
		return isDebug;
	}

}
